<template>
  <div>
    <el-table :data="warehouseInfos">
      <el-table-column prop="id" label="编号"></el-table-column>
      <el-table-column prop="warName" label="仓库名"></el-table-column>
      <el-table-column label="可提供的商品分类">
        <template slot-scope="scope">
          <el-popover
            placement="top-start"
            title="分类如下："
            width="200"
            trigger="hover"
            :content="scope.row.allWarehouseClassificationName">
            <el-button slot="reference">查看仓库指定的分类</el-button>
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column prop="warMaxStock" label="仓库最大库存"></el-table-column>
      <el-table-column label="操作">
        <template slot="header" slot-scope="scope">
          <el-input
            v-model="warehouseInfo.warName"
            size="mini"
            @blur="search"
            placeholder="输入仓库名搜索"/>
        </template>
        <template slot-scope="scope">
          <el-button size="mini" type="primary" @click="audit(scope.row.id,1)">允许通过</el-button>
          <el-button size="mini" type="danger" @click="audit(scope.row.id,2)">拒绝通过</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div>
      <!-- 分页 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageno"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
    export default {
        name: "checkWarehouseInfo",
        data(){
          return {
            warehouseInfo:{
              id:"",
              isCheck:0,//等待审核
              isDelete:0//未被删除
            },
            warehouseInfos:[],
            pageno: 1,
            pagesize: 5,
            total: 1
          }
        },
        methods:{
          getData(){
            let params=new URLSearchParams();
            params.append("pageno", this.pageno);
            params.append("pagesize", this.pagesize);
            Object.keys(this.warehouseInfo).forEach(item=>{
              params.append(item,this.warehouseInfo[item]);
            })
            //异步，查询未被删除，并且等待审核的仓库申请
            this.$axios.get("warehouseInfo/warehouseInfo.action",{params:this.warehouseInfo}).
            then((response)=> {   //异步调用成功执行
              //将查询到的数据存入对象数组中
              this.warehouseInfos=response.data.records;
              this.total = response.data.total;
            }).catch(function (error) {//异步调用失败执行
              alert(error);
            });
          },
          audit(id,isCheck){
            let warehouseInfo={
              id:id,
              isCheck:isCheck
            }
            //调用异步，进行审核
            this.$axios.post("warehouseInfo/checkWarehouseInfo.action",warehouseInfo)
              .then(res=>{
                if(res.data.x){
                  this.$message.success(res.data.msg);
                }else {
                  this.$message.error(res.data.msg);
                }
                //重新查询一次数据
                this.getData();
              })
              .catch(err=>{
                this.$message.warning(err);
                alert(err);
              })
          },
          search(){//按仓库名搜索
            this.getShopData();
          },
          handleSizeChange(val) {
            //每页范围
            this.pagesize = val;
            this.getShopData();
          },
          handleCurrentChange(val) {
            //当前页
            this.pageno = val;
            this.getShopData();
          }
        },
        created() {
          this.getData();
        }
    }
</script>

<style scoped>

</style>
